<?php

class WrBasic extends BaseWrBasic
{
  public function getName()
  {
    $c = new Criteria();
    $c->add(WrMemberPeer::ID, $this->getMemberId());
    $member = WrMemberPeer::doSelectOne($c);
    return $member->getName();
  }
  
  public function getIssuesByCategory($cat)
  {
    $c = new Criteria();
    $c->add(WrIssuePeer::CATEGORY, $cat);
    return WrIssuePeer::doSelect($c);
  }
  
  public function getOthersByCategory($cate)
  {
    $c = new Criteria();
    $c->add(WrOthersPeer::CATEGORY, $cat);
    return WrOthersPeer::doSelect($c);
  }
  
  public function getCategoryDistribution()
  {
    $issues = $this->getWrIssues(new Criteria());
    $others = $this->getWrOtherss(new Criteria());
    $ret = null;
    foreach ($issues as $issue) {
      if (!isset($ret[$issue->getCategory()])) {
        $ret[$issue->getCategory()]['count'] = 1;
        $ret[$issue->getCategory()]['hours'] = $issue->getHour();
      } else {
        $ret[$issue->getCategory()]['count']++;
        $ret[$issue->getCategory()]['hours'] += $issue->getHour();
      }
    }
      
    foreach ($others as $other) {
      if (!isset($ret[$other->getCategory()])) {
        $ret[$other->getCategory()]['count'] = 1;
        $ret[$other->getCategory()]['hours'] = $other->getHour();
      } else {
        $ret[$other->getCategory()]['count']++;
        $ret[$other->getCategory()]['hours'] += $other->getHour();
      }
    }
    
    return array('name' => $this->getName(), 'memid' => $this->getMemberId(),
      'date1' => $this->getDate1(), 
      'date2' => $this->getDate2(),
      'distribution' => $ret
    );
  }
  
  public function getHourDistribution()
  {
    
  }
}
